#include <iostream>
#include<algorithm>
using namespace std;
const int N = 2e6 + 10;
typedef long long LL;
struct node
{
    LL a;
    LL b;
}p[N];
LL n, m;
LL M=1e5;
bool cmp(node& x, node& y)
{
    return x.a < y.a;
}
LL min(LL x, LL y)
{
    if (x < y) return x;
    else return y;
}
int main()
{
    // 请在此输入您的代码
    cin >> n >> m;
    for (LL i = 1;i <= n;i++)
    {
        cin >> p[i].a;
    }
    for (LL i = 1;i <= n;i++)
    {
        cin >> p[i].b;
        M = min(p[i].a + p[i].b, M);//找到最矮的那个
    }
    sort(p + 1, p + 1 + n, cmp);
    //开补
    for (LL i = 1;i <= n;i++)
    {
        if (p[i].a > M) { cout << M << endl;return 0; }
        if (p[i + 1].a > p[i].a)
        {
            if (m >= i * (p[i + 1].a - p[i].a)) m -= i * (p[i + 1].a - p[i].a);
            else
            {
                LL c=0;
                //说明牌不够用
                while (m>=i)
                {
                    m -= i;
                    c++;//计算层数
                }
                //判断一下这个层数是否超了
                if (p[i].a + c > M)
                {
                    cout << M << endl;
                    return 0;
                }
                cout << p[i].a + c << endl;
                return 0;
            }
        }
    }
    return 0;
}